<?php defined('SYSPATH') or die('No direct script access.');

// Пользователи
class Controller_Admin_Users extends Controller_Admin_Base
{
	public function action_account()
	{ 
        $message = null;
        $new_user = null;
        
        $errors = array();
               
        // Редактирование настроек
        if ($this->request->method() == HTTP_Request::POST)
        {            
            $action = $this->request->post('action');
            
            if($action == 'edit_user')
            { 
                try
                {
                    $new_user = $this->user_model->update_user($this->request->post());
                    //Auth::instance()->login();
                
                    $_POST = array();
                    
                    $message = 'Сохранено!';    
                }   
                catch(ORM_Validation_Exception $e)
                {
                    $message = 'Ошибка, смотрите подсказки под полями!';
                    
                    $errors = $e->errors('models');
                }            
                
            }
        }
        
        if($new_user)
            $user = $new_user;
        else
            $user = Auth::instance()->get_user();
        
		$title = 'Ваш профиль';
        $content = new View('admin/users/account_tpl');
        $content->user     = $user;
        $content->message  = $message;
        $content->errors   = $errors;
        
        
        $menu = array(
            'menu'    => 7,
            'submenu' => 70
        );
        
        $this->print_template($title, $content, $menu);
	}
} // End Admin_Users
